<!--　继承母版-->
{% extends 'base.html' %}
<!--　导入Django Haystack自定义模板标签-->
{% load highlight %}{% block main %}
<!--　query 变量保存搜索关键词，如果存在query就循环取出每条记录对象 -->
{% if query %}
<!--　page.object_list保存Blog Index类传给每页的对象集合　-->
{% for result in page.object_list %}
<article class="blog ">
    <header class="entry-header">
        <h1 class="entry-title">
            <!--　文章标题如有搜索关键词则高亮显示-->
            <a href="{{ result.object.get_absolute_url }}">
                {% highlight result.object.title with query %}
            </a>
        </h1>
        <div class="entry-meta-detail">
            <span class="blog-category">
                <a href="{% url 'blog:category' result.object.category.pk %}">
                    {{ result.object.category.name }}
                </a>
            </span>
            <span class="blog-date">
                <a href="#">
                    <time class="entry-date" datetime="{{ result.object.created_time }}">{{ result.object.created_time }}</time>
                </a>
            </span>
            <span class="blog-author">
                <a href="#">{{ result.object.author }}</a>
            </span>
            <span class="comments-link">
                <a href="{{ result.object.get_absolute_url }}#comment-area">
                    <span class="views-count">
                        <a href="{{ result.object.get_absolute_url }}">{{ result.object.views }} 阅读</a>
                    </span>
        </div>
    </header>
    <div class="entry-content clearfix">
        <!--　文章内容如有搜索关键词则高亮显示-->
        <p>{% highlight result.object.body with query %}</p>
    </div>
</article>
{% empty %}
<div class="no-blog">没有搜索到你想要的结果！</div>
{% endfor %}
<!--　Django Haystack 自动对搜索结果进行分页处理，并将其传给模板一个 page 对象，下面是一个简单分页的代码-->
{% if page.has_previous or page.has_next %}
<div>
    {% if page.has_previous %}
    <a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo;Previous{% if page.has_previous %}</a>
    {% endif %}　　　 |{% if page.has_next %}
    <a href="?q={{ query }}&amp;page={{page.next_page_number }}">
        {%endif %}Next&raquo;{% if page.has_next %}
    </a>
    {% endif %}
</div>
{% endif %}
{% else %}请输入搜索关键词{% endif %}
{% endblock main %}